package com.woniuxy.education.controller;

import com.woniuxy.education.entity.*;
import com.woniuxy.education.mapper.SchoolMapper;
import com.woniuxy.education.service.SchoolService;
import com.woniuxy.education.service.StudentService;
import com.woniuxy.education.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/school")
public class SchoolController extends ExceptionCenter{


    @Autowired
    SchoolService schoolService;

    @RequestMapping("/allschool")
    public List<Allschool> findSchool() {

        List<Allschool> allschools = schoolService.findAllSchool();

        return allschools;
    }

    @GetMapping("/updateschool")
    public ResponseResult updateSchool(@RequestParam int id,@RequestParam String school_password) {

        ResponseResult responseResult =new ResponseResult();

        if(schoolService.updateSchool(id,school_password)){
            responseResult.setCode(200);
            responseResult.setMessage("修改成功");
            return responseResult;
        }else {
            responseResult.setCode(400);
            responseResult.setMessage("修改失败,请稍后再试");
            return responseResult;
        }
    }

    @GetMapping("/updateschoolmaster")
    public ResponseResult updateSchoolMaster(@RequestParam int uid,@RequestParam String password){

        ResponseResult responseResult =new ResponseResult();

        if(schoolService.updateSchoolMaster(uid,password)){
            responseResult.setCode(200);
            responseResult.setMessage("修改成功");
            return responseResult;
        }else {
            responseResult.setCode(400);
            responseResult.setMessage("修改失败,请稍后再试");
            return responseResult;
        }
    }

    @RequestMapping("/schoolcontrast")
    public List<School_Contrast> findAllSchoolContrast(){

        List<School_Contrast> schoolContrasts = schoolService.findAllSchoolContrast();
        return schoolContrasts;
    }
}
